﻿<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8" />
    <title>Seminar: Test/SeminarTest/SeminarTest.cs Source File</title>
    <link href="/Content/Help.css" rel="stylesheet" type="text/css" />
    <link href="/Content/css/tabs.css" rel="stylesheet" type="text/css" />
    <link href="/Content/css/doxygen.css" rel="stylesheet" type="text/css" />
</head>
<body>
    <div id="header">
        <img id="logo" alt="StateForge" src="/Content/Images/StateForgeLogo.png" />
        <div id="title">
            <h1>
                C# examples using state machines generated by StateBuilderDotNet
            </h1>
            <h3>
                Seminar: Test/SeminarTest/SeminarTest.cs Source File
            </h3>
        </div>
        <div id="menucontainer">
            <ul id="menu">
                <li><a href="/">Home</a></li>
                <li><a href="/Home/Download">Downloads</a></li>
                <li><a href="/Help/state-machine-tools.aspx">Help</a></li>
                <li><a href="/Home/Faq">F.A.Q</a></li>
                <li><a href="/Home/About">Contact us</a></li>
            </ul>
        </div>
    </div>
<!-- Generated by Doxygen 1.7.4 -->
  <div id="navrow1" class="tabs">
    <ul class="tablist">
      <li><a href="index.html"><span>Main&#160;Page</span></a></li>
      <li><a href="namespaces.html"><span>Namespaces</span></a></li>
      <li><a href="annotated.html"><span>Classes</span></a></li>
      <li class="current"><a href="files.html"><span>Files</span></a></li>
    </ul>
  </div>
  <div id="navrow2" class="tabs2">
    <ul class="tablist">
      <li><a href="files.html"><span>File&#160;List</span></a></li>
      <li><a href="globals.html"><span>File&#160;Members</span></a></li>
    </ul>
  </div>
<div class="header">
  <div class="headertitle">
<div class="title">Test/SeminarTest/SeminarTest.cs</div>  </div>
</div>
<div class="contents">
<a href="_seminar_test_8cs.html">Go to the documentation of this file.</a><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 ﻿
<a name="l00002"></a>00002 <span class="keyword">namespace </span>StateForge.Examples.Seminar
<a name="l00003"></a>00003 {
<a name="l00004"></a>00004     <span class="keyword">using</span> System;
<a name="l00005"></a>00005     <span class="keyword">using</span> NUnit.Framework;
<a name="l00006"></a>00006     <span class="keyword">using</span> StateForge.StateMachine;
<a name="l00007"></a>00007     <span class="keyword">using</span> Rhino.Mocks;
<a name="l00008"></a>00008 
<a name="l00009"></a>00009     [TestFixture]
<a name="l00010"></a><a class="code" href="class_state_forge_1_1_examples_1_1_seminar_1_1_seminar_test.html">00010</a>     <span class="keyword">class </span><a class="code" href="class_state_forge_1_1_examples_1_1_seminar_1_1_seminar_test.html">SeminarTest</a>
<a name="l00011"></a>00011     {
<a name="l00012"></a><a class="code" href="class_state_forge_1_1_examples_1_1_seminar_1_1_seminar_test.html#a148dfe1a9cd76d77982d4f1d43f95312">00012</a>         <span class="keyword">private</span> SeminarContext <a class="code" href="class_state_forge_1_1_examples_1_1_seminar_1_1_seminar_test.html#a148dfe1a9cd76d77982d4f1d43f95312">context</a>;  
<a name="l00013"></a><a class="code" href="class_state_forge_1_1_examples_1_1_seminar_1_1_seminar_test.html#af59cd000ef7d55550bedd27158469e87">00013</a>         <span class="keyword">private</span> <a class="code" href="class_state_forge_1_1_examples_1_1_seminar_1_1_seminar_actuator.html" title="SeminarActuator performs the actions.">SeminarActuator</a> <a class="code" href="class_state_forge_1_1_examples_1_1_seminar_1_1_seminar_test.html#af59cd000ef7d55550bedd27158469e87">actuator</a>;
<a name="l00014"></a><a class="code" href="class_state_forge_1_1_examples_1_1_seminar_1_1_seminar_test.html#a0a8c6cfabdd2aaa5a6d963277c60ea2a">00014</a>         <span class="keyword">private</span> MockRepository <a class="code" href="class_state_forge_1_1_examples_1_1_seminar_1_1_seminar_test.html#a0a8c6cfabdd2aaa5a6d963277c60ea2a">repository</a>;
<a name="l00015"></a><a class="code" href="class_state_forge_1_1_examples_1_1_seminar_1_1_seminar_test.html#a51689cfe45ef9316efe7690815ae0676">00015</a>         <span class="keyword">private</span> IObserver <a class="code" href="class_state_forge_1_1_examples_1_1_seminar_1_1_seminar_test.html#a51689cfe45ef9316efe7690815ae0676">observer</a>;
<a name="l00016"></a><a class="code" href="class_state_forge_1_1_examples_1_1_seminar_1_1_seminar_test.html#a7d938ef2d40c0701945fc704d90c3ea2">00016</a>         <span class="keyword">private</span> <span class="keyword">static</span> String contextName = <span class="stringliteral">&quot;SeminarContext&quot;</span>;
<a name="l00017"></a><a class="code" href="class_state_forge_1_1_examples_1_1_seminar_1_1_seminar_test.html#a90699eaeed4211c54993d760fa58fd1c">00017</a>         <span class="keyword">private</span> <span class="keywordtype">string</span> current, next, <a class="code" href="class_state_forge_1_1_examples_1_1_seminar_1_1_seminar_test.html#a90699eaeed4211c54993d760fa58fd1c">transition</a>;
<a name="l00018"></a>00018 
<a name="l00019"></a><a class="code" href="class_state_forge_1_1_examples_1_1_seminar_1_1_seminar_test.html#adc64d9017bb62ca92a855c144c02c060">00019</a>         <span class="keyword">private</span> <a class="code" href="class_state_forge_1_1_examples_1_1_seminar_1_1_student.html">Student</a> alice, beatrice, <a class="code" href="class_state_forge_1_1_examples_1_1_seminar_1_1_seminar_test.html#adc64d9017bb62ca92a855c144c02c060">carla</a>;
<a name="l00020"></a>00020 
<a name="l00021"></a>00021         [SetUp]
<a name="l00022"></a><a class="code" href="class_state_forge_1_1_examples_1_1_seminar_1_1_seminar_test.html#a8cc6946423a913397533871c74e8878a">00022</a>         <span class="keyword">public</span> <span class="keywordtype">void</span> Setup()
<a name="l00023"></a>00023         {
<a name="l00024"></a>00024             repository = <span class="keyword">new</span> MockRepository();
<a name="l00025"></a>00025             this.actuator = <span class="keyword">new</span> <a class="code" href="class_state_forge_1_1_examples_1_1_seminar_1_1_seminar_actuator.html" title="SeminarActuator performs the actions.">SeminarActuator</a>();
<a name="l00026"></a>00026             observer = repository.StrictMock&lt;IObserver&gt;();
<a name="l00027"></a>00027             this.context = <span class="keyword">new</span> SeminarContext(this.actuator);
<a name="l00028"></a>00028             this.context.Observer = observer;
<a name="l00029"></a>00029 
<a name="l00030"></a>00030             this.alice = <span class="keyword">new</span> <a class="code" href="class_state_forge_1_1_examples_1_1_seminar_1_1_student.html">Student</a>() { Name = <span class="stringliteral">&quot;Alice&quot;</span> };
<a name="l00031"></a>00031             this.beatrice = <span class="keyword">new</span> <a class="code" href="class_state_forge_1_1_examples_1_1_seminar_1_1_student.html">Student</a>() { Name = <span class="stringliteral">&quot;Beatrice&quot;</span> };
<a name="l00032"></a>00032             this.carla = <span class="keyword">new</span> <a class="code" href="class_state_forge_1_1_examples_1_1_seminar_1_1_student.html">Student</a>() { Name = <span class="stringliteral">&quot;Carla&quot;</span> };
<a name="l00033"></a>00033         }
<a name="l00034"></a>00034 
<a name="l00035"></a>00035         [TearDown]
<a name="l00036"></a><a class="code" href="class_state_forge_1_1_examples_1_1_seminar_1_1_seminar_test.html#aaf99f3caf3ed1b0cfb77a4cffdcccc56">00036</a>         <span class="keyword">public</span> <span class="keywordtype">void</span> TearDown()
<a name="l00037"></a>00037         {
<a name="l00038"></a>00038 
<a name="l00039"></a>00039         }
<a name="l00040"></a>00040 
<a name="l00041"></a>00041         [Test]
<a name="l00042"></a><a class="code" href="class_state_forge_1_1_examples_1_1_seminar_1_1_seminar_test.html#a38db8161c5ee1789980ce826103de6c4">00042</a>         <span class="keyword">public</span> <span class="keywordtype">void</span> Start()
<a name="l00043"></a>00043         {
<a name="l00044"></a>00044             <span class="keyword">using</span> (repository.Record())
<a name="l00045"></a>00045             {
<a name="l00046"></a>00046                 <span class="keyword">using</span> (repository.Ordered())
<a name="l00047"></a>00047                 {
<a name="l00048"></a>00048                     Expect.Call(() =&gt; this.observer.OnEntry(contextName, <span class="stringliteral">&quot;Root&quot;</span>));
<a name="l00049"></a>00049                     Expect.Call(() =&gt; this.observer.OnEntry(contextName, <span class="stringliteral">&quot;Enrollment&quot;</span>));
<a name="l00050"></a>00050                     Expect.Call(() =&gt; this.observer.OnEntry(contextName, <span class="stringliteral">&quot;OpenForEnrollment&quot;</span>));
<a name="l00051"></a>00051                 }
<a name="l00052"></a>00052             }
<a name="l00053"></a>00053 
<a name="l00054"></a>00054             <span class="keyword">using</span> (repository.Playback())
<a name="l00055"></a>00055             {
<a name="l00056"></a>00056                 this.context.EnterInitialState();
<a name="l00057"></a>00057             }
<a name="l00058"></a>00058         }
<a name="l00059"></a>00059 
<a name="l00060"></a>00060         [Test]
<a name="l00061"></a><a class="code" href="class_state_forge_1_1_examples_1_1_seminar_1_1_seminar_test.html#ad169688cdc75e9933c120d2a10257c32">00061</a>         <span class="keyword">public</span> <span class="keywordtype">void</span> StandardEnrollment()
<a name="l00062"></a>00062         {
<a name="l00063"></a>00063             <span class="keyword">using</span> (repository.Record())
<a name="l00064"></a>00064             {
<a name="l00065"></a>00065                 <span class="keyword">using</span> (repository.Ordered())
<a name="l00066"></a>00066                 {
<a name="l00067"></a>00067                     <span class="comment">// this.context.EvStudentEnrollRequest(alice);</span>
<a name="l00068"></a>00068                     current = <span class="stringliteral">&quot;OpenForEnrollment&quot;</span>; next = <span class="stringliteral">&quot;OpenForEnrollment&quot;</span>; transition = <span class="stringliteral">&quot;StudentEnrollRequest&quot;</span>;
<a name="l00069"></a>00069                     Expect.Call(() =&gt; this.observer.OnTransitionBegin(contextName, current, next, transition));
<a name="l00070"></a>00070                     Expect.Call(() =&gt; this.observer.OnTransitionEnd(contextName, current, next, transition));
<a name="l00071"></a>00071 
<a name="l00072"></a>00072                     <span class="comment">// this.context.EvTermStarted();</span>
<a name="l00073"></a>00073                     current = <span class="stringliteral">&quot;OpenForEnrollment&quot;</span>; next = <span class="stringliteral">&quot;BeingTaught&quot;</span>; transition = <span class="stringliteral">&quot;TermStarted&quot;</span>;
<a name="l00074"></a>00074                     Expect.Call(() =&gt; this.observer.OnTransitionBegin(contextName, current, next, transition));
<a name="l00075"></a>00075                     Expect.Call(() =&gt; this.observer.OnExit(contextName, current));
<a name="l00076"></a>00076                     Expect.Call(() =&gt; this.observer.OnExit(contextName, <span class="stringliteral">&quot;Enrollment&quot;</span>));
<a name="l00077"></a>00077                     Expect.Call(() =&gt; this.observer.OnEntry(contextName, next));
<a name="l00078"></a>00078                     Expect.Call(() =&gt; this.observer.OnTransitionEnd(contextName, current, next, transition));
<a name="l00079"></a>00079 
<a name="l00080"></a>00080                     <span class="comment">// this.context.EvClassesEnded();</span>
<a name="l00081"></a>00081                     current = <span class="stringliteral">&quot;BeingTaught&quot;</span>; next = <span class="stringliteral">&quot;FinalExams&quot;</span>; transition = <span class="stringliteral">&quot;ClassesEnded&quot;</span>;
<a name="l00082"></a>00082                     Expect.Call(() =&gt; this.observer.OnTransitionBegin(contextName, current, next, transition));
<a name="l00083"></a>00083                     Expect.Call(() =&gt; this.observer.OnExit(contextName, current));
<a name="l00084"></a>00084                     Expect.Call(() =&gt; this.observer.OnEntry(contextName, next));
<a name="l00085"></a>00085                     Expect.Call(() =&gt; this.observer.OnTransitionEnd(contextName, current, next, transition));
<a name="l00086"></a>00086 
<a name="l00087"></a>00087                     <span class="comment">// this.context.EvExamsClosed();</span>
<a name="l00088"></a>00088                     current = <span class="stringliteral">&quot;FinalExams&quot;</span>; next = <span class="stringliteral">&quot;End&quot;</span>; transition = <span class="stringliteral">&quot;ExamsClosed&quot;</span>;
<a name="l00089"></a>00089                     Expect.Call(() =&gt; this.observer.OnTransitionBegin(contextName, current, next, transition));
<a name="l00090"></a>00090                     Expect.Call(() =&gt; this.observer.OnExit(contextName, current));
<a name="l00091"></a>00091                     Expect.Call(() =&gt; this.observer.OnEntry(contextName, next));
<a name="l00092"></a>00092                     Expect.Call(() =&gt; this.observer.OnTransitionEnd(contextName, current, next, transition));
<a name="l00093"></a>00093 
<a name="l00094"></a>00094                 }
<a name="l00095"></a>00095             }
<a name="l00096"></a>00096 
<a name="l00097"></a>00097             <span class="keyword">using</span> (repository.Playback())
<a name="l00098"></a>00098             {
<a name="l00099"></a>00099                 this.context.StudentEnrollRequest(this.alice);
<a name="l00100"></a>00100 
<a name="l00101"></a>00101                 this.context.TermStarted();
<a name="l00102"></a>00102 
<a name="l00103"></a>00103                 this.context.ClassesEnded();
<a name="l00104"></a>00104 
<a name="l00105"></a>00105                 this.context.ExamsClosed();
<a name="l00106"></a>00106             }
<a name="l00107"></a>00107         }
<a name="l00108"></a>00108 
<a name="l00109"></a>00109         [Test]
<a name="l00110"></a><a class="code" href="class_state_forge_1_1_examples_1_1_seminar_1_1_seminar_test.html#a9829d3cf5b886e5e5b326a393419836a">00110</a>         <span class="keyword">public</span> <span class="keywordtype">void</span> DisastrousEnrollment()
<a name="l00111"></a>00111         {
<a name="l00112"></a>00112             <span class="keyword">using</span> (repository.Record())
<a name="l00113"></a>00113             {
<a name="l00114"></a>00114                 <span class="keyword">using</span> (repository.Ordered())
<a name="l00115"></a>00115                 {
<a name="l00116"></a>00116                     <span class="comment">// this.context.EvStudentEnrollRequest(alice);</span>
<a name="l00117"></a>00117                     current = <span class="stringliteral">&quot;OpenForEnrollment&quot;</span>; next = <span class="stringliteral">&quot;OpenForEnrollment&quot;</span>; transition = <span class="stringliteral">&quot;StudentEnrollRequest&quot;</span>;
<a name="l00118"></a>00118                     Expect.Call(() =&gt; this.observer.OnTransitionBegin(contextName, current, next, transition));
<a name="l00119"></a>00119                     Expect.Call(() =&gt; this.observer.OnTransitionEnd(contextName, current, next, transition));
<a name="l00120"></a>00120 
<a name="l00121"></a>00121                     <span class="comment">// this.context.EvStudentEnrollRequest(beatrice);</span>
<a name="l00122"></a>00122                     current = <span class="stringliteral">&quot;OpenForEnrollment&quot;</span>; next = <span class="stringliteral">&quot;Full&quot;</span>; transition = <span class="stringliteral">&quot;StudentEnrollRequest[(mySeminar.StudentsCount + 1) == mySeminar.MaxStudents]&quot;</span>;
<a name="l00123"></a>00123                     Expect.Call(() =&gt; this.observer.OnTransitionBegin(contextName, current, next, transition));
<a name="l00124"></a>00124                     Expect.Call(() =&gt; this.observer.OnExit(contextName, current));
<a name="l00125"></a>00125                     Expect.Call(() =&gt; this.observer.OnEntry(contextName, next));
<a name="l00126"></a>00126                     Expect.Call(() =&gt; this.observer.OnTransitionEnd(contextName, current, next, transition));
<a name="l00127"></a>00127 
<a name="l00128"></a>00128                     <span class="comment">// this.context.EvStudentEnrollRequest(alice);</span>
<a name="l00129"></a>00129                     current = <span class="stringliteral">&quot;Full&quot;</span>; next = <span class="stringliteral">&quot;Full&quot;</span>; transition = <span class="stringliteral">&quot;StudentEnrollRequest&quot;</span>;
<a name="l00130"></a>00130                     Expect.Call(() =&gt; this.observer.OnTransitionBegin(contextName, current, next, transition));
<a name="l00131"></a>00131                     Expect.Call(() =&gt; this.observer.OnTransitionEnd(contextName, current, next, transition));
<a name="l00132"></a>00132 
<a name="l00133"></a>00133                     <span class="comment">// this.context.EvStudentDropped(this.beatrice);</span>
<a name="l00134"></a>00134                     current = <span class="stringliteral">&quot;Full&quot;</span>; next = <span class="stringliteral">&quot;Full&quot;</span>; transition = <span class="stringliteral">&quot;StudentDropped[mySeminar.HasStudentInWaitingList()]&quot;</span>;
<a name="l00135"></a>00135                     Expect.Call(() =&gt; this.observer.OnTransitionBegin(contextName, current, next, transition));
<a name="l00136"></a>00136                     Expect.Call(() =&gt; this.observer.OnTransitionEnd(contextName, current, next, transition));
<a name="l00137"></a>00137 
<a name="l00138"></a>00138                     <span class="comment">// this.context.EvStudentDropped(this.alice);</span>
<a name="l00139"></a>00139                     current = <span class="stringliteral">&quot;Full&quot;</span>; next = <span class="stringliteral">&quot;OpenForEnrollment&quot;</span>; transition = <span class="stringliteral">&quot;StudentDropped&quot;</span>;
<a name="l00140"></a>00140                     Expect.Call(() =&gt; this.observer.OnTransitionBegin(contextName, current, next, transition));
<a name="l00141"></a>00141                     Expect.Call(() =&gt; this.observer.OnExit(contextName, current));
<a name="l00142"></a>00142                     Expect.Call(() =&gt; this.observer.OnEntry(contextName, next));
<a name="l00143"></a>00143                     Expect.Call(() =&gt; this.observer.OnTransitionEnd(contextName, current, next, transition));
<a name="l00144"></a>00144 
<a name="l00145"></a>00145                     <span class="comment">// this.context.EvTermStarted();</span>
<a name="l00146"></a>00146                     current = <span class="stringliteral">&quot;OpenForEnrollment&quot;</span>; next = <span class="stringliteral">&quot;BeingTaught&quot;</span>; transition = <span class="stringliteral">&quot;TermStarted&quot;</span>;
<a name="l00147"></a>00147                     Expect.Call(() =&gt; this.observer.OnTransitionBegin(contextName, current, next, transition));
<a name="l00148"></a>00148                     Expect.Call(() =&gt; this.observer.OnExit(contextName, current));
<a name="l00149"></a>00149                     Expect.Call(() =&gt; this.observer.OnExit(contextName, <span class="stringliteral">&quot;Enrollment&quot;</span>));
<a name="l00150"></a>00150                     Expect.Call(() =&gt; this.observer.OnEntry(contextName, next));
<a name="l00151"></a>00151                     Expect.Call(() =&gt; this.observer.OnTransitionEnd(contextName, current, next, transition));
<a name="l00152"></a>00152 
<a name="l00153"></a>00153                     <span class="comment">// this.context.EvStudentDropped(this.carla);</span>
<a name="l00154"></a>00154                     current = <span class="stringliteral">&quot;BeingTaught&quot;</span>; next = <span class="stringliteral">&quot;End&quot;</span>; transition = <span class="stringliteral">&quot;StudentDropped[mySeminar.IsEmpty()]&quot;</span>;
<a name="l00155"></a>00155                     Expect.Call(() =&gt; this.observer.OnTransitionBegin(contextName, current, next, transition));
<a name="l00156"></a>00156                     Expect.Call(() =&gt; this.observer.OnExit(contextName, current));
<a name="l00157"></a>00157                     Expect.Call(() =&gt; this.observer.OnEntry(contextName, next));
<a name="l00158"></a>00158                     Expect.Call(() =&gt; this.observer.OnTransitionEnd(contextName, current, next, transition));
<a name="l00159"></a>00159 
<a name="l00160"></a>00160                 }
<a name="l00161"></a>00161             }
<a name="l00162"></a>00162 
<a name="l00163"></a>00163             <span class="keyword">using</span> (repository.Playback())
<a name="l00164"></a>00164             {
<a name="l00165"></a>00165                 this.context.StudentEnrollRequest(this.alice);
<a name="l00166"></a>00166                 this.context.StudentEnrollRequest(this.beatrice);
<a name="l00167"></a>00167                 this.context.StudentEnrollRequest(this.carla);
<a name="l00168"></a>00168 
<a name="l00169"></a>00169                 this.context.StudentDropped(this.beatrice);
<a name="l00170"></a>00170                 this.context.StudentDropped(this.alice);
<a name="l00171"></a>00171 
<a name="l00172"></a>00172                 this.context.TermStarted();
<a name="l00173"></a>00173                 this.context.StudentDropped(this.carla);
<a name="l00174"></a>00174 
<a name="l00175"></a>00175 
<a name="l00176"></a>00176             }
<a name="l00177"></a>00177         }
<a name="l00178"></a>00178 
<a name="l00179"></a>00179        
<a name="l00180"></a>00180     }
<a name="l00181"></a>00181 }
</pre></div></div>
</div>
﻿<div id="footer">
    <hr />
    <p>
        Copyright &copy; 2011 StateForge.</p>
    <hr />
</div>
</body> </html> 
